package com.mingqijia.gassafety.shared.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 设备类型
 * @author guoliang.lao
 * @version v1.0.1
 * @date 2022年02月23日
 */
@Getter
@RequiredArgsConstructor
public enum EquipmentType {

    GAS_ALARM_CONTROLLER("气体报警控制器","Gas_alarm_controller"),
    INDEPENDENT_GAS_DETECTOR("独立式可燃气体探测器","Independent_gas_detector"),
    POINT_TYPE_GAS_DETECTOR("点型可燃气体探测器","Point_type_gas_detector"),
    HOME_GAS_DETECTOR("家用燃气报警器","home_gas_detector"),
    OTHER("","");

    private final String name;
    private final String code;
    public static final String DICT_CODE = "Equipment_type";

    public static EquipmentType parse(String code) {
        List<EquipmentType> filtered = Arrays.stream(EquipmentType.values())
                .filter(item -> Objects.equals(item.getCode(), code))
                .collect(Collectors.toList());
        return CollectionUtils.isEmpty( filtered ) ? OTHER : filtered.get(0);
    }

}
